﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using API.Models;
using PPG.DataAccess;
using System.Configuration;
using System.Data;
using System.Xml;
using System.Text;


namespace API.Controllers
{
    public class UserController : ApiController
    {
        public DataSourceCommunicator dsComm = new DataSourceCommunicator();
    
        public IHttpActionResult GetUser(int id)
        {
            dsComm.AddParameter("@ParamLoginID", "1001");
            string data = dsComm.ExecuteStoredProcedure("spGetUserByLoginID");
            XmlTextReader xReader = new XmlTextReader(data, XmlNodeType.Document, null);
            DataSet UserDataSet = new DataSet();
            UserDataSet.ReadXml(xReader);
            //var product = products.FirstOrDefault((p) => p.Id == id);

            User CurrentUser = new User(UserDataSet.Tables[0].Rows[0]["Username"].ToString(), UserDataSet.Tables[0].Rows[0]["Password"].ToString());
            if (CurrentUser == null)
            {
                return NotFound();
            }
            return Ok(CurrentUser);
        }

        
    }
}
